/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  聊天室
	/// module : structs
	/// </summary>
	public class ChatRoomPOD : IPOD 
    {
        public readonly static Func<ChatRoomPOD> FACTORY = () => new ChatRoomPOD();
		public static Func<ChatRoomPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public int roomNumber;
		/// <summary>
        /// 
        /// </summary>
		public int onlineCount;
		/// <summary>
        /// 
        /// </summary>
        private List<SChatPOD> m_msg;
		
		
        public List<SChatPOD> msg
        {
            get
            {
                if(m_msg == null)
                {
                    m_msg = new();
                }
                return m_msg;
            }
            private set => m_msg = value;
        }
        public List<SChatPOD> unsafe_msg
        {
        	get => m_msg;
        	set => m_msg = value;
        }
		
		/*-- constructors --*/
		public ChatRoomPOD() {}
		public ChatRoomPOD(int roomNumber, int onlineCount, List<SChatPOD> msg) {
			this.roomNumber = roomNumber;
			this.onlineCount = onlineCount;
			this.m_msg = msg;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(roomNumber);
            _out.Write_int(onlineCount);
            _out.Write_list_pod(m_msg);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            roomNumber = _in.Read_int();
            if(!_in.HasRemaining()) return;
            onlineCount = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_msg = _in.Read_list_pod<SChatPOD>(SChatPOD.DynamicFactory);
        }
		
		public ChatRoomPOD Clone() {
            ChatRoomPOD o = DynamicFactory();
            o.roomNumber = roomNumber;
            o.onlineCount = onlineCount;
            if (m_msg != null) {
                o.m_msg = m_msg.ConvertAll(o => o?.Clone());
            }
            return o;
        }
        
        public void Clear() {
            roomNumber = default;
            onlineCount = default;
            m_msg = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "ChatRoomPOD [";
			str += "roomNumber=";
			str += roomNumber;
			str += ", onlineCount=";
			str += onlineCount;
			str += ", msg=";
			str += m_msg.ToString<SChatPOD>();
			str += "]";
			return str;
		}
		
	}
}